#include "Context.h"
#include <QDebug>

#include "UI/ModRun/Output/FactoryOutput.h"


Context::Context()
{
    QString strOutput = "策略模式 构造";
    qDebug() << strOutput;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutput };
        pOutPut->OutPut(outList);
    }
}
Context::~Context()
{
    QString strOutput = "策略模式 析构";
    qDebug() << strOutput;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutput };
        pOutPut->OutPut(outList);
    }
}

void Context::SetStrategy(std::shared_ptr<IStrategy> pStrategyIn)
{
    QString strOutput = "设置了新策略:";
    qDebug() << strOutput;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutput };
        pOutPut->OutPut(outList);
    }

    m_pStrategy = pStrategyIn;
}

//打印报价;
void Context::printPrice(double s)
{
    if (m_pStrategy == nullptr)
    {
        return;
    }
    qDebug() << "将策略的调用封装，实现晚绑定，增加新策略不影响原有策略;";

    QString strOutput = "打印报价: " + QString::number(m_pStrategy->getPrice(s));
    qDebug() << strOutput;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutput };
        pOutPut->OutPut(outList);
    }
}
